package com.jzo2o.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jzo2o.customer.domain.BankAccount;
import com.jzo2o.customer.mapper.BankAccountMapper;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import org.springframework.stereotype.Service;

/**
 * @author zmm
 * @description 针对表【bank_account(银行账户)】的数据库操作Service实现
 * @createDate 2025-06-19 11:19:56
 */
@Service
public class IBankAccountServiceImpl extends ServiceImpl<BankAccountMapper, BankAccount> implements IBankAccountService {
    @Override
    public void saveOrUpdateBankAccount(BankAccountUpsertReqDTO dto) {
        //获取服务人员/机构id
        dto.setId(UserContext.currentUserId());
        if (dto.getType()!=null && dto.getType()==1){
            dto.setType(3);
        }
        //转为BankAccount实体
        BankAccount bankAccount = BeanUtil.copyProperties(dto, BankAccount.class);
        //保存or更新
        saveOrUpdate(bankAccount);
    }

    /**
     * 获取当前用户银行账户信息
     *
     * @return
     */
    @Override
    public BankAccountResDTO getCurrentUserBankAccount() {
        Long userId = UserContext.currentUserId();
        BankAccount bankAccount = lambdaQuery()
                .eq(BankAccount::getId, userId)
                .one();
        return BeanUtil.copyProperties(bankAccount, BankAccountResDTO.class);
    }
}





